<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>资源列表</title>
</head>
<link type="text/css" rel="stylesheet" th:href="@{~/bootstrap-3.3.7/css/bootstrap.css}"/>
<script type="text/javascript" th:src="@{~/bootstrap-3.3.7/js/jquery.js}"></script>
<script type="text/javascript" th:src="@{~/bootstrap-3.3.7/js/bootstrap.js}"></script>
<body>

<div class="container">

    <a href="javascript:void(0)" class="btn btn-success btn-primary btn-xs" th:onclick="'javascript:add();'">添加</a>
    <a href="javascript:void(0)" class="btn btn-success btn-primary btn-xs" th:onclick="'javascript:addPrant();'">添加其父目录</a>
    <a href="javascript:void(0)" class="btn btn-success btn-primary btn-xs" th:onclick="'javascript:chakan();'">查看删除的资源</a>
    <table class="table table-bordered table-hover">
        <tr>
            <td>编号</td>
            <td>权限名称</td>
            <td>url</td>
            <td>介绍</td>
            <td>创建时间</td>
            <td>状态</td>
            <td>操作</td>
        </tr>
        <!-- 该出不允许 出现空格  在role 后面逗号后面跟的状态变量-->
        <tr th:each="resources,resourcesStat : ${resources}">
            <td th:text="${resourcesStat.count}"></td>
            <td th:text="${resources.name}">xx</td>
            <td th:text="${resources.url}">xx</td>
            <td th:text="${resources.description}">xx</td>
            <td th:text="${#dates.format(resources.createTime,'yyyy-MM-dd HH:mm:ss')}">创建时间</td>
            <td th:text="${resources.status == 1}? '禁用' : '启用'">xx</td>
            <script>
                function update(id){
                    location.href="/resource/toUpdateResouce?id="+id;
                }

                function delete1(ids){

                    $.post(
                        "/resource/deleteResource",
                        {
                            ids:ids
                        },
                        function(data){
                            if (data == 1) {
                                alert("成功");
                                location.href = "/resource/listResource";
                            } else if (data == 3){
                                alert("该资源还与角色绑定,请先接触绑定, 才可以删除");
                            }
                            else {
                                alert("失败")
                            }
                        },
                        "json"
                    );

                }

                function add(){
                    location.href="/resource/toAddResource";
                }
                function addPrant(){
                    location.href="/resource/toAddPrant";
                }
                function chakan(){
                    location.href="/resource/chakan";
                }
            </script>
            <td>
                <a href="javascript:void(0)" th:onclick="'javascript:update(\''+${resources.id}+'\');'" class="btn btn-info btn-primary btn-xs">修改</a>
                <a href="javascript:void(0)" class="btn btn-danger btn-primary btn-xs" th:onclick="'javascript:delete1(\''+${resources.id}+'\');'">删除</a>
            </td>
        </tr>
    </table>


</div>

</body>
</html>